package com.playwright.util.zhihu2toutiao;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Playwright;

import java.nio.file.Path;

/**
 * @author liyanhao
 * @Date 2024-01-17 11:43
 */
public class PlaywrightUtils {
    /**
     * 获取浏览器对象
     * @param playwright
     * @return
     */
    public static Browser getBrowser(Playwright playwright) {
        BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
        launchOptions.setExecutablePath(Path.of("C:\\Users\\lyh\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"));
        launchOptions.setHeadless(false).setSlowMo(500);
        Browser browser = playwright.chromium().connectOverCDP("http://localhost:9222");
        return browser;
    }


}
